package org.example.sort;

import java.util.Scanner;

public class quick {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
        int low=0;
        int high=nums.length-1;
        quicksort(nums,low,high);
        for (int num:nums){
            System.out.print(num+"  ");
        }
    }

    private static void quicksort(int[] nums, int low, int high) {
        if(low<high){
            int pi=partations(nums,low,high);
            quicksort(nums,low,pi-1);
            quicksort(nums,pi+1,high);
        }
    }

    private static int partations(int[] nums, int low, int high) {
        int pivot=nums[low];
        while (low<high){
            if(low<high&&nums[high]>=pivot){
                high--;
            }
            nums[low]=nums[high];
            if(low<high&&nums[low]<=pivot){
                low++;
            }
            nums[high]=nums[low];
        }
        nums[low]=pivot;
        return low;
    }
}
